package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ConditionalOnClass条件注解，用来判断该环境环境中是否存在指定的类
 * 其中DispatcherServlet是Spring MVC的核心类，
 * 因此，通过判断这个类存不存在来进行判断是否将该bean加入IOC容器中
 * @author xiaopeng
 * @version 1.0
 */
@Configuration
@ConditionalOnClass(DispatcherServlet.class) //网关模块不需要该配置类
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }
}
